package com.cykj.controller;

import com.cykj.service.DetailsService;
import com.cykj.util.ResponseDto;
import com.cykj.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/details")
@RestController
public class DetailsController {
    @Autowired
    private DetailsService detailsService;

    @RequestMapping("/getAllDetails")
    public ResponseDto getAllDetails(@RequestBody PageVo vo) {
        return detailsService.getAllDetail(vo.getPageCurr(), vo.getPageSize());
    }

    @RequestMapping("/changeStatus")
    public ResponseDto changeStatus(int proStatus, int detailsId) {
        if (proStatus == 2) {
            proStatus = 0;
        } else if (proStatus == 1) {
            proStatus = 1;
        }
        ResponseDto dto = detailsService.changeStatus(proStatus, detailsId);
        return dto;
    }

    @RequestMapping("/deleteDetail")
    public ResponseDto deleteDetail(int detailsId) {
        return detailsService.deleteDetail(detailsId);
    }

    @RequestMapping("/alterDetails")
    public ResponseDto alterDetails(int detailsId, String detailsName, String detailsUnit, String detailsUp, String detailsDown) {
        return detailsService.alterDepart(detailsId, detailsName, detailsUnit, detailsUp, detailsDown);
    }

    @RequestMapping("/searchDetailsInfo")
    public ResponseDto searchDetailsInfo(String value, int pageCurr, int pageSize) {
        return detailsService.searchDetailsInfo(value, pageCurr, pageSize);
    }

    @RequestMapping("/getAllDetailsName")
    public ResponseDto getAllDetailsName() {
        return detailsService.getAllDetailsName();
    }


    @RequestMapping("/commitDelete")

    public ResponseDto commitDelete(String checkedDetails) {
        try {
            return detailsService.commitDelete(checkedDetails);
        } catch (Exception e) {
            return new ResponseDto(-1, "操作失败了", null);
        }
    }
    @RequestMapping("/fatherDepartIdIsExist")
    public ResponseDto fatherDepartIdIsExist(String fatherDepartId){
        return detailsService.fatherDepartIdIsExist(fatherDepartId);
    }
    @RequestMapping("/addDetailCommit")
    public ResponseDto addDetailCommit(String detailName, String fatherDepartId, String detailUnit, String detailUp, String detailDown, String status){
        return detailsService.addDetailCommit(detailName, fatherDepartId, detailUnit, detailUp, detailDown, status);
    }

}
